package com.gongpingjialoan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.utility.AgentGroupData;
import com.gongpingjialoan.utility.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2016/10/28.
 */
public class AgentGridAdapter extends BaseAdapter {

    private List<AgentGroupData> agentGroupDatas;

    private Context mContext;

    private LayoutInflater mLayoutInflater;

    public AgentGridAdapter(Context context, List<AgentGroupData> agentGroupDatas) {
        mContext = context;
        this.agentGroupDatas = agentGroupDatas;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return agentGroupDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(
                    R.layout.grid_item, null, false);
        }
        TextView tv1 = BaseViewHolder.get(convertView, R.id.name);
        TextView tv2 = BaseViewHolder.get(convertView, R.id.value);
        tv1.setText(agentGroupDatas.get(position).getName());
        tv2.setText(agentGroupDatas.get(position).getValue());
        return  convertView;
    }
}
